{% extends 'base.html' %}
{% load i18n %}

{% block title %}{{ page_title }} - {{ block.super }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4 flex-wrap">
    <h1 class="h2 mb-0"><i class="bi bi-calendar-check me-2"></i> {{ page_title }}</h1>
     <div>
         {% if selected_field %} {# Show link to view all if currently filtered #}
             <a href="{% url 'planting_records:record_list' %}" class="btn btn-outline-secondary btn-sm me-2"><i class="bi bi-list-ul"></i> {% trans "查看所有记录" %}</a>
             <a href="{% url 'planting_records:record_add_for_field' selected_field.pk %}" class="btn btn-success"><i class="bi bi-plus-lg"></i> {% trans "为当前田块添加记录" %}</a>
         {% else %}
              <a href="{% url 'planting_records:record_add' %}" class="btn btn-success"><i class="bi bi-plus-lg"></i> {% trans "添加新记录" %}</a>
         {% endif %}
     </div>
</div>

{% if records %}
    <div class="list-group shadow-sm">
        {% for record in records %}
        <a href="{{ record.get_absolute_url }}" class="list-group-item list-group-item-action record-card">
            <div class="d-flex w-100 justify-content-between">
                <h5 class="mb-1 text-primary">{{ record.rice_variety }} <small class="text-muted">({% trans "田块" %}: {{ record.field.name }})</small></h5>
                <span class="badge bg-secondary rounded-pill">{{ record.get_planting_method_display }}</span>
            </div>
            <p class="mb-1">
                <i class="bi bi-calendar-event text-secondary me-1"></i> {% trans "种植日期" %}: {{ record.planting_date|date:"Y-m-d" }}
                {% if record.expected_harvest_date %}
                 | <i class="bi bi-calendar-range text-secondary ms-2 me-1"></i> {% trans "预计收获" %}: {{ record.expected_harvest_date|date:"Y-m-d" }}
                {% endif %}
            </p>
            <p class="mb-1"><small class="text-muted">{{ record.notes|truncatewords:15|default:"" }}</small></p>
            <small class="text-muted">{% trans "记录人" %}: {{ record.owner.username }} | {% trans "更新于" %}: {{ record.updated_at|date:"Y-m-d H:i" }}</small>
        </a>
        {% endfor %}
    </div>

    {% include 'partials/_pagination.html' %}

{% else %}
    <div class="alert alert-info text-center" role="alert">
       <i class="bi bi-info-circle me-2"></i>
       {% if selected_field %}
            {% blocktrans with field_name=selected_field.name %}田块 "{{ field_name }}" 还没有任何种植记录。{% endblocktrans %}
             <a href="{% url 'planting_records:record_add_for_field' selected_field.pk %}" class="alert-link ms-2">{% trans "立即添加" %}</a>
       {% else %}
            {% trans "您还没有添加任何种植记录。" %}
             <a href="{% url 'planting_records:record_add' %}" class="alert-link ms-2">{% trans "立即添加" %}</a>
       {% endif %}
    </div>
{% endif %}
{% endblock %}